package com.fc.example;

import android.app.Activity;
import android.util.Log;
import android.widget.Toast;

import com.anythink.core.api.ATAdConst;
import com.anythink.core.api.AdError;
import com.anythink.nativead.api.ATNative;
import com.anythink.nativead.api.ATNativeNetworkListener;

import java.util.HashMap;
import java.util.Map;

public class ATNativeNew {
    public static ATNative mATNative;
    public static String mMediaId = "b65a7a9b5b7fb8";

    public static void getATNative(Activity activity) {
        if (mATNative == null) {
            mATNative = new ATNative(activity, mMediaId, new ATNativeNetworkListener() {
                @Override
                public void onNativeAdLoaded() {
                    Toast.makeText(activity, "加载成功", Toast.LENGTH_SHORT).show();
                    Log.i("test", "onNativeAdLoaded");
                }

                @Override
                public void onNativeAdLoadFail(AdError adError) {
                    Log.i("test", "onNativeAdLoadFail, " + adError.getFullErrorInfo());
                    Toast.makeText(activity, "加载失败" + adError.getFullErrorInfo(), Toast.LENGTH_SHORT).show();
                }
            });
            mATNative.setAdSourceStatusListener(new FeedExpressActivity.ATAdSourceStatusListenerImpl());
        }
    }

    public static void request(Activity activity) {
        getATNative(activity);
        if (mATNative.getNativeAd() == null) {
            Map<String, Object> localExtra = new HashMap<>();
            localExtra.put(ATAdConst.KEY.AD_WIDTH, 350); // 单位是dp
            localExtra.put(ATAdConst.KEY.AD_HEIGHT, 300); // 单位是dp
            mATNative.setLocalExtra(localExtra);
            mATNative.makeAdRequest();
            Log.i("test", "makeAdRequest");
        }
    }

}
